package o;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import o.ah.g;

public class ca {
    private cu ˊ;
    private final bx ˋ;
    private final View ˎ;
    private cu ˏ;
    private int ॱ = -1;
    private cu ᐝ;

    public ca(View view) {
        this.ˎ = view;
        this.ˋ = bx.ˋ();
    }

    public void ˋ(AttributeSet attributeSet, int i) {
        cw ॱ = cw.ॱ(this.ˎ.getContext(), attributeSet, g.ᴵॱ, i, 0);
        try {
            if (ॱ.ᐝ(g.ᵕ)) {
                this.ॱ = ॱ.ॱॱ(g.ᵕ, -1);
                ColorStateList ˋ = this.ˋ.ˋ(this.ˎ.getContext(), this.ॱ);
                if (ˋ != null) {
                    ˏ(ˋ);
                }
            }
            if (ॱ.ᐝ(g.ᵎॱ)) {
                ViewCompat.ˎ(this.ˎ, ॱ.ॱ(g.ᵎॱ));
            }
            if (ॱ.ᐝ(g.ᕀ)) {
                ViewCompat.ˊ(this.ˎ, cl.ˏ(ॱ.ॱ(g.ᕀ, -1), null));
            }
            ॱ.ॱ();
        } catch (Throwable th) {
            ॱ.ॱ();
        }
    }

    public void ˎ(int i) {
        this.ॱ = i;
        ˏ(this.ˋ != null ? this.ˋ.ˋ(this.ˎ.getContext(), i) : null);
        ˋ();
    }

    public void ˋ(Drawable drawable) {
        this.ॱ = -1;
        ˏ(null);
        ˋ();
    }

    public void ˊ(ColorStateList colorStateList) {
        if (this.ˊ == null) {
            this.ˊ = new cu();
        }
        this.ˊ.ˋ = colorStateList;
        this.ˊ.ˎ = true;
        ˋ();
    }

    public ColorStateList ˎ() {
        return this.ˊ != null ? this.ˊ.ˋ : null;
    }

    public void ॱ(Mode mode) {
        if (this.ˊ == null) {
            this.ˊ = new cu();
        }
        this.ˊ.ˏ = mode;
        this.ˊ.ˊ = true;
        ˋ();
    }

    public Mode ॱ() {
        return this.ˊ != null ? this.ˊ.ˏ : null;
    }

    public void ˋ() {
        Drawable background = this.ˎ.getBackground();
        if (background == null) {
            return;
        }
        if (!ˊ() || !ˎ(background)) {
            if (this.ˊ != null) {
                bx.ˏ(background, this.ˊ, this.ˎ.getDrawableState());
            } else if (this.ˏ != null) {
                bx.ˏ(background, this.ˏ, this.ˎ.getDrawableState());
            }
        }
    }

    void ˏ(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.ˏ == null) {
                this.ˏ = new cu();
            }
            this.ˏ.ˋ = colorStateList;
            this.ˏ.ˎ = true;
        } else {
            this.ˏ = null;
        }
        ˋ();
    }

    private boolean ˊ() {
        int i = VERSION.SDK_INT;
        if (i > 21) {
            if (this.ˏ != null) {
                return true;
            }
            return false;
        } else if (i != 21) {
            return false;
        } else {
            return true;
        }
    }

    private boolean ˎ(@NonNull Drawable drawable) {
        if (this.ᐝ == null) {
            this.ᐝ = new cu();
        }
        cu cuVar = this.ᐝ;
        cuVar.ॱ();
        ColorStateList ʾ = ViewCompat.ʾ(this.ˎ);
        if (ʾ != null) {
            cuVar.ˎ = true;
            cuVar.ˋ = ʾ;
        }
        Mode ʿ = ViewCompat.ʿ(this.ˎ);
        if (ʿ != null) {
            cuVar.ˊ = true;
            cuVar.ˏ = ʿ;
        }
        if (!cuVar.ˎ && !cuVar.ˊ) {
            return false;
        }
        bx.ˏ(drawable, cuVar, this.ˎ.getDrawableState());
        return true;
    }
}
